﻿using System;
using UnityEngine;
using UnityEngine.Events;

// Token: 0x020003B9 RID: 953
public class RadioButtonGroup : MonoBehaviour
{
	// Token: 0x17000252 RID: 594
	// (get) Token: 0x060017C0 RID: 6080 RVA: 0x0009C968 File Offset: 0x0009AB68
	public ToggleButton[] ToggleButtons
	{
		get
		{
			return this.toggleButtons;
		}
	}

	// Token: 0x17000253 RID: 595
	// (get) Token: 0x060017C1 RID: 6081 RVA: 0x0009C970 File Offset: 0x0009AB70
	// (set) Token: 0x060017C2 RID: 6082 RVA: 0x0009C978 File Offset: 0x0009AB78
	public bool AllowOFF
	{
		get
		{
			return this.allowOFF;
		}
		set
		{
			this.allowOFF = value;
		}
	}

	// Token: 0x17000254 RID: 596
	// (get) Token: 0x060017C3 RID: 6083 RVA: 0x0009C984 File Offset: 0x0009AB84
	// (set) Token: 0x060017C4 RID: 6084 RVA: 0x0009C98C File Offset: 0x0009AB8C
	public int Value
	{
		get
		{
			return this.onNo;
		}
		set
		{
			this.Change(value);
		}
	}

	// Token: 0x060017C5 RID: 6085 RVA: 0x0009C998 File Offset: 0x0009AB98
	private void Awake()
	{
		this.SetupToggleButtons();
	}

	// Token: 0x060017C6 RID: 6086 RVA: 0x0009C9A0 File Offset: 0x0009ABA0
	private void Update()
	{
		if (this.change)
		{
			this.action.Invoke(this.onNo);
			this.change = false;
		}
	}

	// Token: 0x060017C7 RID: 6087 RVA: 0x0009C9C8 File Offset: 0x0009ABC8
	private void OnToggleButton(int no, bool flag)
	{
		if (this.change)
		{
			return;
		}
		if (flag)
		{
			if (this.onNo != no)
			{
				this.onNo = no;
				this.change = true;
			}
			this.ChangeToggleButtonsOff(no);
		}
		else if (!this.allowOFF)
		{
			if (this.allowOffCheck)
			{
				this.toggleButtons[no].ChangeValue(true, false);
			}
		}
		else
		{
			this.change = true;
			this.onNo = -1;
		}
	}

	// Token: 0x060017C8 RID: 6088 RVA: 0x0009CA48 File Offset: 0x0009AC48
	private void ChangeToggleButtonsOff(int on)
	{
		this.allowOffCheck = false;
		for (int i = 0; i < this.toggleButtons.Length; i++)
		{
			if (i != on)
			{
				this.toggleButtons[i].ChangeValue(false, true);
			}
		}
		this.allowOffCheck = true;
	}

	// Token: 0x060017C9 RID: 6089 RVA: 0x0009CA94 File Offset: 0x0009AC94
	private void ChangeToggleButtonsValue(int on, bool invoke)
	{
		this.allowOffCheck = false;
		for (int i = 0; i < this.toggleButtons.Length; i++)
		{
			this.toggleButtons[i].ChangeValue(i == on, invoke);
		}
		this.allowOffCheck = true;
	}

	// Token: 0x060017CA RID: 6090 RVA: 0x0009CADC File Offset: 0x0009ACDC
	public void Change(int no)
	{
		this.onNo = no;
		this.ChangeToggleButtonsValue(no, true);
	}

	// Token: 0x060017CB RID: 6091 RVA: 0x0009CAF0 File Offset: 0x0009ACF0
	public void Change(int no, bool invoke)
	{
		this.onNo = no;
		this.ChangeToggleButtonsValue(no, invoke);
	}

	// Token: 0x060017CC RID: 6092 RVA: 0x0009CB04 File Offset: 0x0009AD04
	private void SetupToggleButtons()
	{
		for (int i = 0; i < this.toggleButtons.Length; i++)
		{
			int no = i;
			this.toggleButtons[i].action.AddListener(delegate(bool val)
			{
				this.OnToggleButton(no, val);
			});
			if (this.toggleButtons[i].Value)
			{
				this.onNo = i;
			}
		}
	}

	// Token: 0x060017CD RID: 6093 RVA: 0x0009CB78 File Offset: 0x0009AD78
	public void SetToggleButtons(ToggleButton[] sets)
	{
		if (this.toggleButtons != null)
		{
			for (int i = 0; i < this.toggleButtons.Length; i++)
			{
				int no = i;
				this.toggleButtons[i].action.RemoveListener(delegate(bool val)
				{
					this.OnToggleButton(no, val);
				});
			}
		}
		this.toggleButtons = new ToggleButton[sets.Length];
		for (int j = 0; j < sets.Length; j++)
		{
			this.toggleButtons[j] = sets[j];
		}
		this.SetupToggleButtons();
	}

	// Token: 0x04001B43 RID: 6979
	[SerializeField]
	private ToggleButton[] toggleButtons;

	// Token: 0x04001B44 RID: 6980
	[SerializeField]
	private bool allowOFF = true;

	// Token: 0x04001B45 RID: 6981
	public RadioButtonGroup.RadioButtonGroupEvent action = new RadioButtonGroup.RadioButtonGroupEvent();

	// Token: 0x04001B46 RID: 6982
	private bool change;

	// Token: 0x04001B47 RID: 6983
	private int onNo = -1;

	// Token: 0x04001B48 RID: 6984
	private bool allowOffCheck = true;

	// Token: 0x020003BA RID: 954
	[Serializable]
	public class RadioButtonGroupEvent : UnityEvent<int>
	{
	}
}
